/**
 * `const` test
 * @author Kelvin Pan
 * @date 04/03/2012
 **/

#include <iostream>
using namespace std;

int main()
{
	int *foo = new int(2048);
	int *bar = new int(1024);
	cout << "*foo = "<<*foo <<" @"<<foo<<endl;
	cout << "*bar = "<<*bar <<" @"<<bar<<endl;


	/**
	 * pointer to a const int
	 * only address can be changed
	 **/
	int const *pointer_to_a_const_int = foo;//同 const int *pointer_to_a_const_int
	cout << "*pointer_to_a_const_int = " << *pointer_to_a_const_int <<" @"<<pointer_to_a_const_int << endl;//2048

	// *pointer_to_a_const_int (value) cannot be changed
	//*pointer_to_a_const_int = *bar; //<-- ERROR

	// pointer_to_a_const_int (address) can be changed
	pointer_to_a_const_int = bar;

	cout << "*pointer_to_a_const_int = " << *pointer_to_a_const_int <<" @"<<pointer_to_a_const_int << endl;//1024


	/**
	 * const pointer to int
	 * only value can be changed
	 **/
	int *const const_pointer_to_int = foo;
	cout << "*const_pointer_to_int = " << *const_pointer_to_int << " @" <<const_pointer_to_int << endl;//2048

	// *const_pointer_to_int (value) can be changed
	*const_pointer_to_int = *bar;

	// const_pointer_to_int (address) cannot be changed
	//const_pointer_to_int = bar; //<-- ERROR

	cout << "*const_pointer_to_int = " <<*const_pointer_to_int <<" @"<<const_pointer_to_int << endl;//1024
	return 0;
}

